# -*- coding:utf-8 -*-

import logging
from Enterprise_wechat_Interface.po import utils
from Enterprise_wechat_Interface.po.basepage import BasePage


class MemberManage(BasePage):
    data = utils.get_faker()
    def add_member(self):
        """
        新增人员接口
        :return:
        """
        req_data = {
            "method": 'post',
            "url": f"https://aaa/cgi-bin/user/create?access_token={self.token}",
            "data": {
                "userid": f"{self.data['get_userid']}",
                "name": f"{self.data['get_name']}",
                "mobile": f"{self.data['get_phone']}",
                "department": [1]},
            "headers": None
        }
        # json 代表把数据转为json格式发送
        r = self.send(req_data)
        # data不是json格式，其他类型的数据
        # r=requests.post(url=url,data=json.dumps(data),verify=False)
        logging.info(f"新增人员姓名：{self.data['get_name']}")
        logging.info(f"新增人员帐号：{self.data['get_userid']}")
        return r

    def delete_member(self,userid):
        """
        删除人员接口
        :return:
        """
        req_data = {
            "method": 'get',
            "url": f"https://aaa/cgi-bin/user/delete?access_token={self.token}&userid={userid}",
            "data":None,
            "headers":None
        }
        r=self.send(req_data)
        logging.info(f"删除帐号：{userid}")
        return r

    def update_member(self,userid):
        """
        更新成员信息
        :return:
        """
        req_data = {
            "method": 'post',
            "url": f"https://aaa/cgi-bin/user/update?access_token={self.token}",
            "data": {
            "userid": userid,
            "position": f"{self.data['get_position']}",
            "mobile": f"{self.data['get_phone']}",
            "email": f"{self.data['get_email']}",
            "address": f"{self.data['get_address']}"
        },
            "headers":None
        }
        r=self.send(req_data)
        logging.info(f"更新职务：{self.data['get_position']}")
        logging.info(f"更新手机号：{self.data['get_phone']}")
        logging.info(f"更新邮箱：{self.data['get_email']}")
        logging.info(f"更新地址：{self.data['get_address']}")
        return r

    def query_member(self,userid):
        """
        查询人员接口
        :param userid:
        :return:
        """
        req_data = {
            "method": 'get',
            "url": f"https://aaa/cgi-bin/user/get?access_token={self.token}&userid={userid}",
            "data": None,
            "headers": None
        }
        r=self.send(req_data)
        return r
